package com.lance.code.synctaskapplication.slice;

import com.lance.code.synctaskapplication.MyTask;
import com.lance.code.synctaskapplication.OhosAsyncTask;
import com.lance.code.synctaskapplication.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.eventhandler.EventHandler;
import ohos.eventhandler.EventRunner;

public class MainAbilitySlice extends AbilitySlice {
    EventHandler handler = new EventHandler(EventRunner.current());
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        findComponentById(ResourceTable.Id_text_helloworld).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                MyTask task = new MyTask(getContext());
                task.execute();

                handler.postTask(new Runnable() {
                    @Override
                    public void run() {

                        task.cancel();
                    }
                },2000);
            }
        });
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
